﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.DAL.CommonDAL;
using MINERP.DAL.Statistics;
using MINERP.BLL.Statistics;
using MINERP.MODEL.FoundationModel;
using DevExpress.XtraEditors.Controls;

namespace MINERP.Statistics.Forms
{
    public partial class FrmShopAccountMove : Form
    {
        public FrmShopAccountMove()
        {
            InitializeComponent();
        }

        private void FrmShopAccountMove_Load(object sender, EventArgs e)
        {
            //初始化时间和商户列表
            DEStart.DateTime = DateTime.Now.Date;
            DEEND.DateTime = DateTime.Now.Date.AddDays(1);

            //cmbShop.Properties.DataSource = ShopDAL.GetALLShop();
            //cmbShop.Properties.DisplayMember = "shopName";
            //cmbShop.Properties.ValueMember = "ShopId";
            BingdingType();
        }

        private void BingdingType()
        {
            comboBoxEditType.Properties.Items.Add("充值");
            comboBoxEditType.Properties.Items.Add("冲抵");
            comboBoxEditType.Properties.Items.Add("清零");
            comboBoxEditType.Properties.Items.Add("编辑");

            foreach (CheckedListBoxItem item in comboBoxEditType.Properties.Items)
            {
                item.CheckState = CheckState.Checked;
            }


        }
        BillIndexBLL2 _bllIndel2 = new BillIndexBLL2();
        private void textEditHelpCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (Keys.Enter == e.KeyCode)
            {
                cmbShop.DisplayMember = "ShopName";
                cmbShop.ValueMember = "ShopId";
                cmbShop.DataSource = _bllIndel2.GetShopInfoByHelpCode(textEditHelpCode.Text.Trim());



            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Shop_Info info = (Shop_Info)cmbShop.SelectedItem;
            if (info == null)
            {
                MessageBox.Show("请选择商户");
                return;
            }
            DateTime start = DEStart.DateTime.Date;
            DateTime end = DEEND.DateTime.AddDays(1).Date.AddSeconds(-1);

            simpleButton1.Enabled = false;
            string tpyeStr = "";
            foreach (CheckedListBoxItem item in comboBoxEditType.Properties.Items)
            {
                if (item.CheckState == CheckState.Checked)
                {
                    if (((string)item.Value).Equals("充值"))
                    {
                        tpyeStr += "0"+",";
                    }
                    else if (((string)item.Value).Equals("冲抵"))
                    {
                        tpyeStr += "1" + ",";
                    }
                    else if (((string)item.Value).Equals("清零"))
                    {
                        tpyeStr += "2" + ",";
                    }
                    else if (((string)item.Value).Equals("编辑"))
                    {
                        tpyeStr += "3" + ",";
                    }
                }
            }
            tpyeStr = tpyeStr.Trim(',');
            this.Cursor = Cursors.WaitCursor;
            DataSet dsResult = ShopBalanceMoveDAL.GetAccoundRecord(info.ShopId, start, end, tpyeStr);
            //dsResult.Tables[0].DefaultView.Sort = "ShopBlanceCrushRecordId ASC";
            DataTable table = dsResult.Tables[0];
            DataRow[] rows = table.Select("", "ShopBlanceCrushRecordId ASC");
            DataTable tblCopy = new DataTable(table.TableName);
            tblCopy = table.Clone();
            foreach (DataRow row in rows)
            {
                tblCopy.ImportRow(row);
            } 
            //dsResult.WriteXml(@"C:\Windows\xmldata\商户帐户资金流动记录.xml", XmlWriteMode.WriteSchema);
           //tblCopy
            tblCopy.WriteXml(@"C:\Windows\xmldata\商户帐户资金流动记录.xml", XmlWriteMode.WriteSchema);

            
            string shopName = cmbShop.Text.Trim();
            report1.Preview = previewControl1;
            report1.Load(Application.StartupPath + "\\商户帐户资金流动记录.frx");
            report1.RegisterData(dsResult);
            report1.SetParameterValue("shopName", shopName);
            previewControl1.Refresh();
            //previewControl1.Show();
            report1.Show();
            this.Cursor = Cursors.Default;
            simpleButton1.Enabled = true;

        }

        private void textEditHelpCode_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
